package com.juzipi.demo.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class JdbcUpdateDemo {
    public static void main(String[] args) {
        Connection connection = null;
        Statement statement = null;
        try {
            //获取连接对象
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/springboot?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone = GMT", "zhangsan", "lsjxj");
            //定义sql
            String s = "update practice set age = 21 where id = 1";
            //获取执行sql的对象
            statement = connection.createStatement();
            //执行sql
            int i = statement.executeUpdate(s);
            System.out.println(i);
            if (i > 0){
                System.out.println("SUCCESS");
            }else {
                System.out.println("ERROR");
            }


        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } finally {
            //释放资源
            if (statement != null) {
                try {
                    statement.close();
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                }
            }
            if (connection != null){
                try {
                    connection.close();
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                }
            }
        }


    }
}
